package org.garbagecan.xstreamstudy.alias;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.SingleValueConverter;

public class Test {
	public static void main(String[] args) {
		simpleTest();
		classAliasTest();
		omitEntriesTest();
		attributeAliasTest();
	}
	public static void simpleTest() {
		System.out.println("------------simpleTest------------");
		Blog teamBlog = new Blog(new Author("Guilherme Silveira"));
		teamBlog.add(new Entry("first", "My first blog entry."));
		teamBlog.add(new Entry("tutorial","Today we have developed a nice alias tutorial. Tell your friends! NOW!"));

		XStream xstream = new XStream();
		
		System.out.println(xstream.toXML(teamBlog));		
	}
	public static void classAliasTest() {
		System.out.println("------------classAliasTest------------");
		Blog teamBlog = new Blog(new Author("Guilherme Silveira"));
		teamBlog.add(new Entry("first", "My first blog entry."));
		teamBlog.add(new Entry("tutorial","Today we have developed a nice alias tutorial. Tell your friends! NOW!"));

		XStream xstream = new XStream();
		xstream.alias("blog", Blog.class);
		xstream.alias("entry", Entry.class);
		
		System.out.println(xstream.toXML(teamBlog));
	}
	public static void omitEntriesTest() {
		System.out.println("------------omitEntriesTest------------");
		Blog teamBlog = new Blog(new Author("Guilherme Silveira"));
		teamBlog.add(new Entry("first", "My first blog entry."));
		teamBlog.add(new Entry("tutorial","Today we have developed a nice alias tutorial. Tell your friends! NOW!"));

		XStream xstream = new XStream();
		xstream.alias("blog", Blog.class);
		xstream.alias("entry", Entry.class);
		xstream.addImplicitCollection(Blog.class, "entries");

		System.out.println(xstream.toXML(teamBlog));
	}
	public static void attributeAliasTest() {
		System.out.println("------------attributeAliasTest------------");
		Blog teamBlog = new Blog(new Author("Guilherme Silveira"));
		teamBlog.add(new Entry("first", "My first blog entry."));
		teamBlog.add(new Entry("tutorial","Today we have developed a nice alias tutorial. Tell your friends! NOW!"));

		XStream xstream = new XStream();
		xstream.alias("blog", Blog.class);
		xstream.alias("entry", Entry.class);
		xstream.addImplicitCollection(Blog.class, "entries");
		xstream.useAttributeFor(Blog.class, "author");
		xstream.registerConverter(new AuthorConverter());
		
		System.out.println(xstream.toXML(teamBlog));
	}
}
